package org.example.pictools.service;

import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.imaging.jpeg.JpegProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

@Service
public class PicService {


	public Map<String,String> picS(File file){
		Tag tag=null;
		Metadata metadata;
		Map<String,String> map=new HashMap<>();
		try {
			metadata= JpegMetadataReader.readMetadata(file);
			Iterator<Directory> it=metadata.getDirectories().iterator();
			while (it.hasNext()){
				Directory exif= it.next();
				Iterator<Tag> tags=exif.getTags().iterator();
				while (tags.hasNext()){
					tag=tags.next();
					map.put("****************","*****************");
					map.put(tag.getTagName(),tag.getDescription());
				}
			}
			return  map;
		} catch (JpegProcessingException e) {
			throw new RuntimeException(e);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	public Map<String,String> picO(File file){
		Tag tag=null;
		Metadata metadata;
		Map<String,String> map=new HashMap<>();
		try {
			metadata= JpegMetadataReader.readMetadata(file);
			Iterator<Directory> it=metadata.getDirectories().iterator();
			while (it.hasNext()){
				Directory exif= it.next();
				Iterator<Tag> tags=exif.getTags().iterator();
				while (tags.hasNext()){
					tag=tags.next();
					map.put("****************","*****************");
					map.put(tag.getTagName(),tag.getDescription());
				}
			}
			return map;
		} catch (JpegProcessingException e) {
			throw new RuntimeException(e);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}
